<%--
  Created by IntelliJ IDEA.
  User: limin
  Date: 2021/8/5
  Time: 18:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*,com.beans.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
    <base href="<%=basePath%>">

    <title></title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">

    <link rel="stylesheet" type="text/css" href="css/edittable.css"  >
    <link rel="stylesheet" type="text/css" href="css/validate.css"  >
    <link rel="stylesheet" type="text/css" href="css/maintable.css">
    <script src="js/jquery-1.8.0.js"></script>
    <script>
        $(function(){
            $("input[type=text],textarea").focus(function(){
                $(this).addClass("input_focus");
            }).blur(function(){
                $(this).removeClass("input_focus");
            });

            $(".form_btn").hover(function(){
                    $(this).css("color","red").css("background","#6FB2DB");
                },

                function(){
                    $(this).css("color","#295568").css("background","#BAD9E3");
                });
        });
    </script>
    <script>
        function checkSub(par){
            $("."+par.id).attr("checked",par.checked)
        }
        function checkParent(parentId){
            $("#"+parentId).removeAttr("checked");
            $("."+parentId).each(function(){
                if (this.checked){
                    $("#"+parentId).attr("checked","checked");
                    return;
                }
            })
        }
    </script>
</head>

<body>
<div class ="div_title">
    <div class="div_titlename"> <img src="images/san_jiao.gif" ><span>角色权限分配:${roleInfo.roleName}</span></div>
</div>

<form action="RoleServlet.do?flag=updateRoleMenu" method="post">
    <input type="hidden" name="roleId" value="${roleInfo.id}">
    <table  class="main_table">
        <tr>
            <th>一级</th>
            <th>二级</th>
        </tr>
        <c:forEach var="m" items="${menuList}">
            <tr>
                <td>
                    <input type="checkbox" name="menuIds" id="${m.id}" value="${m.id}" onclick="checkSub(this)">
                ${m.menuName}
                </td>
                <td>
                    <c:forEach var="m_sub" items="${m.subMenuList}">
                        <input type="checkbox" class="${m.id}" name="menuIds" id="${m_sub.id}" value="${m_sub.id}" onclick="checkParent(${m.id})">${m_sub.menuName} <br>

                    </c:forEach>
                </td>
            </tr>
        </c:forEach>
        <tr>
            <td>
                <input class="form_btn" type="submit" value="提交" onclick="return confirm('确认提交吗')">
                <input type="button" class="form_btn" onclick="window.history.back()" value="返回">
            </td>
            <td></td>
        </tr>
    </table>
</form>
${msg}
</body>
<script>
    var menuIdStr="${menuIdStr}"
    var menuIdArray = menuIdStr.split(",")

    Array.prototype.contains=function (e){
        for (var i = 0; i < this.length; i++) {
            if (this[i]==e){
                return true;
            }

        }
        return false;
    }

    $("input[name=menuIds]").each(function (){
        if (menuIdArray.contains(this.value)){
            this.checked=true;
        }
    })
</script>
</html>
